﻿using AutoMapper.Configuration;
using DJY.Domain.Entity.SystemManage;
using DJY.Domain.ViewModel;
using DJY.Domain.ViewModel.SystemManage;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DJY.Web
{
    public class AutoMapperConfig
    {
        public static void Init()
        {
            MapperConfigurationExpression config = new MapperConfigurationExpression();
            config.CreateMap<SysAreaEntity, SysAreaViewModel>()
                .ForMember(dest => dest.code,opt => opt.MapFrom(src=>src.F_EnCode))
                .ForMember(dest => dest.parent, opt => opt.MapFrom(src => string.IsNullOrEmpty(src.F_ParentId)?"0": src.F_ParentId))
                .ForMember(dest => dest.level, opt => opt.MapFrom(src => src.F_Layers))
                .ForMember(dest => dest.name, opt => opt.MapFrom(src => src.F_FullName))
                .ForMember(dest => dest.shortName, opt => opt.MapFrom(src => src.F_SimpleSpelling))
                .ForMember(dest => dest.sortIdx, opt => opt.MapFrom(src => src.F_SortCode ?? 0))
                .ForMember(dest => dest.desc, opt => opt.MapFrom(src => src.F_Description));
            config.CreateMap<SysModuleEntity, SysModuleViewModel>()
                .ForMember(dest => dest.id, opt => opt.MapFrom(src => src.F_Id))
                .ForMember(dest => dest.name, opt => opt.MapFrom(src => src.F_FullName))
                .ForMember(dest => dest.desc, opt => opt.MapFrom(src => src.F_Description))
                .ForMember(dest => dest.icon, opt => opt.MapFrom(src => src.F_Icon))
                .ForMember(dest => dest.url, opt => opt.MapFrom(src => src.F_UrlAddress))
                .ForMember(dest => dest.sortIdx, opt => opt.MapFrom(src => src.F_SortCode));
            config.CreateMap<SysUserEntity, SysUserViewModel>()
                .ForMember(dest => dest.id, opt => opt.MapFrom(src => src.F_Id))
                .ForMember(dest => dest.account, opt => opt.MapFrom(src => src.F_Account))
                .ForMember(dest => dest.name, opt => opt.MapFrom(src => src.F_RealName))
                .ForMember(dest => dest.nickName, opt => opt.MapFrom(src => src.F_NickName))
                .ForMember(dest => dest.headerPic, opt => opt.MapFrom(src => src.F_HeadIcon))
                .ForMember(dest => dest.department, opt => opt.MapFrom(src => src.Department))
                .ForMember(dest => dest.post, opt => opt.MapFrom(src => src.Duty))
                .ForMember(dest => dest.role, opt => opt.MapFrom(src => src.Role))
                .ForMember(dest => dest.gender, opt => opt.MapFrom(src => src.F_Gender?"男":"女"))
                .ForMember(dest => dest.email, opt => opt.MapFrom(src => src.F_Email))
                .ForMember(dest => dest.enabled, opt => opt.MapFrom(src => src.F_EnabledMark))
                .ForMember(dest => dest.createTime, opt => opt.MapFrom(src => src.F_CreatorTime.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(dest => dest.visitTime, opt => opt.MapFrom(src => src.LastVisitTime.HasValue? src.LastVisitTime.Value.ToString("yyyy-MM-dd HH:mm:ss"):null));
            config.CreateMap<SysOrganizeEntity, SysItemCode>()
                .ForMember(dest => dest.code, opt => opt.MapFrom(src => src.F_EnCode))
                .ForMember(dest => dest.parent, opt => opt.MapFrom(src => src.F_ParentId))
                .ForMember(dest => dest.id, opt => opt.MapFrom(src => src.F_Id))
                .ForMember(dest => dest.text, opt => opt.MapFrom(src => src.F_FullName))
                .ForMember(dest => dest.desc, opt => opt.MapFrom(src => src.F_Description));

            AutoMapper.Mapper.Initialize(config);
        }
    }
}